﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reborn_Server.App1AppHandler;
using App1AppHandler;
using Reborn_WorldServer;

namespace Reborn_Server.App1AppHandler
{
    public class Spell_SummonDagger : TargetSpell
    {
        public void Cast(CreatureBase myCharacter, int CastLevel, long CreatureGUID)
        {
            if (myCharacter.LeftHand != null && myCharacter.RightHand != null)
            {
                if (myCharacter is Character)
                {
                    Character character = (Character)myCharacter;
                    character.PlaySound("Ding", character.MapX, character.MapY);
                    character.SetBusy(false);
                    character.WarmSpell = null;
                    character.Update_Character();
                    character.SendMessage("You must have an empty hand to summon an item","server");
                }
                return;                
            }

            List<MapItem> MapItemsWithin12;
            if (base.InitializeCast(myCharacter, CastLevel, myCharacter.CreatureID, false, out MapItemsWithin12) == false)
                return;

            Weapon summonedDagger = new Weapon(Managers.GameHandler);
            summonedDagger.ID = -1;
            summonedDagger.Accuracy = CastLevel * 9;
            summonedDagger.DmgLow = CastLevel * 5;
            summonedDagger.DmgHigh = CastLevel * 6;
            summonedDagger.Defense = CastLevel;
            summonedDagger.GameUID = Managers.GameHandler.ItemIDGen.GetUID();
            summonedDagger.Bag = true;
            summonedDagger.Belt = true;
            summonedDagger.CanConsume = false;
            summonedDagger.Description = "A dagger summoned by " + myCharacter.Name;
            summonedDagger.Equip = false;
            summonedDagger.ImageURL = "Dagger6";
            summonedDagger.ItemType = "Weapon";
            summonedDagger.MainApp = Managers.GameHandler;
            summonedDagger.Melee = true;
            summonedDagger.Name = "Summoned Dagger";
            summonedDagger.PriceHigh = 0;
            summonedDagger.PriceLow = 0;
            summonedDagger.Range = true;
            summonedDagger.RangeDistance = 4;
            summonedDagger.RangeThrows = true;
            summonedDagger.Skill = "Piercing_1H";
            summonedDagger.Slot = "RightHand";
            summonedDagger.Speed = 2.5M;
            summonedDagger.StamCost = 20;
            summonedDagger.Weight = 1;
            summonedDagger.timerDestroyInterval = 1000 * 60 * 3;

            //LevelRequirement requirement = new LevelRequirement();
            //requirement.LevelRequired = 5;
            //requirement.Required = true;
            //requirement.Skill = "Piercing_1H";

            //summonedDagger.RequirementsAll.Add(requirement);

            if (TargetCreatureBase.RightHand == null)
                TargetCreatureBase.RightHand = summonedDagger;
            else if (TargetCreatureBase.LeftHand == null)
                TargetCreatureBase.LeftHand = summonedDagger;

            TargetCreatureBase.Update_Character();
            TargetCreatureBase.SendMessage("You summon a dagger", "spelldefense");

            foreach (MapItem mapitem in MapItemsWithin12)
            {
                if (Math.Abs(mapitem.MapX - TargetCreatureBase.MapX) <= 4 && Math.Abs(mapitem.MapY - TargetCreatureBase.MapY) <= 4)
                {
                    foreach (CreatureBase creatureBase in mapitem.CreaturesBases)
                    {
                        if (creatureBase is Character)
                        {
                            Character character = (Character)creatureBase;
                            character.AddCreatureBase(TargetCreatureBase);
                        }
                    }
                }
            }
        }

    }
}
